﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using Recon.Portal.Business;
using Recon.Portal.DataObjects;

namespace Recon.Portal.WebUI
{
    public partial class ReconSite : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DateTime currentTime = DateTime.Now;
            try
            {
                currentTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
            }
            catch (TimeZoneNotFoundException exc)
            {
                if (exc != null)
                {
                    currentTime = DateTime.UtcNow.AddHours(5).AddMinutes(30);
                }
            }
            User currentUser = ((User)Session["CurrentUserVO"]);
            if (currentUser != null)
            {
                if (!IsPostBack)
                {
                    lblDateTime.Text = "Welcome " + currentUser.UserName + "! " + currentTime.ToString("MMMM d yyyy, hh:mm tt IST");
                    SiteHeading.InnerText = "Invoice Reconciliation System: " + (string.IsNullOrEmpty(currentUser.CustomerName) ? "[4Circle Internal]" : currentUser.CustomerName);

                    MenuManager objMenuManager = new MenuManager();
                    objMenuManager.populateMenu(mnReconEngine, ((User)Session["CurrentUserVO"]).RoleID,((User)Session["CurrentUserVO"]).CustomerID);
                    Session["IsMainMenuLoaded"] = true;
                }
            }
            else
            {
                lblDateTime.Text = "Welcome Guest!  " + currentTime.ToString("MMMM d yyyy, hh:mm tt IST");

                lgsCurrent.Visible = false;
                mnReconEngine.Visible = false;
            }
        }

        protected void lgsCurrent_LoggedOut(object sender, EventArgs e)
        {
            Session.Abandon();
            Session.Clear();
            FormsAuthentication.SignOut();
        }
    }


}